package com.TestDemo.Test202203To04;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/04/15:12
 * @Description:
 * @Target:
 */
public class CompareTest01 {
    public static void main(String[] args) {

        ComPPP c1 = new ComPPP("zjz1",20,1);
        ComPPP c2 = new ComPPP("zjz2",16,2);
        ComPPP c3 = new ComPPP("zjz3",19,3);
        ComPPP c4 = new ComPPP("zjz4",21,4);
        ComPPP c5 = new ComPPP("zjz5",27,5);
        ComPPP c6 = new ComPPP("zjz6",27,6);
        ComPPP c7 = new ComPPP("zjz7",29,7);



        ComPPP[] comPPPS = new ComPPP[]{c1,c2,c3,c4,c5,c6,c7};




        for (ComPPP comPPP : comPPPS) {
            System.out.print(comPPP+" ");
        }

        System.out.println();
        Arrays.sort(comPPPS,new MyComparator());



//        swap(comPPPS,0,2);
        for (ComPPP comPPP : comPPPS) {
            System.out.print(comPPP+" ");
        }
    /*    for (int i = 0; i < comPPPS.length; i++) {

        }*/




    }

    public static void swap(ComPPP[] comPPPS, int c1, int c2){
        ComPPP temp = new ComPPP();
        temp = comPPPS[c1];
        comPPPS[c1] = comPPPS[c2];
        comPPPS[c2] = temp;

    }



    public static class MyComparator implements Comparator<ComPPP>{
        @Override
        public int compare(ComPPP o1, ComPPP o2) {
            return o1.getAge()- o2.getAge();
        }
    }

    public static class ComPPP {



        private String name;
        private int age;
        private int id;

        @Override
        public String toString() {
            return "ComPPP{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", id=" + id +
                    '}';
        }

        public ComPPP() {
        }

        public ComPPP(String name, int age, int id) {
            this.name = name;
            this.age = age;
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }
    }



}
